package com.bjgzy.rating.mvp.adapter;

import android.view.View;
import android.widget.ImageView;

import com.bjgzy.rating.R;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.eduhzy.ttw.commonsdk.entity.SignUp1ParentData;
import com.eduhzy.ttw.commonsdk.entity.SignUp1SonData;
import com.eduhzy.ttw.commonsdk.holder.AutoBaseViewHolder;

import java.util.List;

/**
 * Created by luoxw on 2016/8/9.
 */
public class ExpandableItemAdapter extends BaseMultiItemQuickAdapter<MultiItemEntity, AutoBaseViewHolder> {
    private static final String TAG = ExpandableItemAdapter.class.getSimpleName();

    public static final int TYPE_LEVEL_0 = 0;
    public static final int TYPE_LEVEL_1 = 1;
    public static final int TYPE_PERSON = 2;

    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public ExpandableItemAdapter(List<MultiItemEntity> data) {
        super(data);
        addItemType(TYPE_LEVEL_0, R.layout.rating_rv_item_sign_up1_parent);
        addItemType(TYPE_LEVEL_1, R.layout.rating_rv_item_sign_up1_son);
    }


    @Override
    protected void convert(final AutoBaseViewHolder holder, final MultiItemEntity item) {
        switch (holder.getItemViewType()) {
            case TYPE_LEVEL_0:
                final SignUp1ParentData lv0 = (SignUp1ParentData) item;
                holder.setText(R.id.tv_name, lv0.getClassifyName());
                ImageView ivIcon = holder.getView(R.id.iv_icon);
                if (lv0.getSonNum() <= 0) {
                    ivIcon.setVisibility(View.GONE);
                } else {
                    ivIcon.setVisibility(View.VISIBLE);
                    if (lv0.isExpanded()) {
                        ivIcon.animate().rotation(90);
                    } else {
                        ivIcon.animate().rotation(0);
                    }
                }
                break;
            case TYPE_LEVEL_1:
                final SignUp1SonData lv1 = (SignUp1SonData) item;
                holder.setText(R.id.tv_name, lv1.getClassifyName());
                break;
            default:
        }
    }
}
